﻿using System;
using System.Drawing;

using Scripni.Chess.Core.Pieces;
using Scripni.Chess.UI.Properties;

namespace Scripni.Chess.UI.ViewModels
{
    /// <summary>
    /// Handles resource operations.
    /// </summary>
    public class ResourceManager
    {
        private ResourceManager()
        {
            
        }
        static ResourceManager()
        {
            PrivateInstance = new ResourceManager();
        }
        private static readonly ResourceManager PrivateInstance;

        /// <summary>
        /// Gets the instance of the class.
        /// </summary>
        public static ResourceManager Instance
        {
            get
            {
                return PrivateInstance;
            }
        }


        public Icon GetPieceIcon(Piece piece)
        {
            if (piece == null) return null;

            if(piece.Color == PieceColor.White)
            {
                return GetWhitePiece(piece);
            }
            else
            {
                return GetDarkPiece(piece);
            }
        }

        private Icon GetWhitePiece(Piece piece)
        {
            if (piece is Pawn)
            {
                return Resources.WhitePawn;
            }
            else if (piece is Bishop)
            {
                return Resources.WhiteBishop;
            }
            else if (piece is Knight)
            {
                return Resources.WhiteKnight;
            }
            else if (piece is Rook)
            {
                return Resources.WhiteRook;
            }
            else if (piece is Queen)
            {
                return Resources.WhiteQueen;
            }
            else if (piece is King)
            {
                return Resources.WhiteKing;
            }
            else
            {
                throw new ArgumentException("Cannot find a visual representation for [ " + piece.GetType() + " ].");
            }
        }

        private Icon GetDarkPiece(Piece piece)
        {
            if (piece is Pawn)
            {
                return Resources.BlackPawn;
            }
            else if (piece is Bishop)
            {
                return Resources.BlackBishop;
            }
            else if (piece is Knight)
            {
                return Resources.BlackKnight;
            }
            else if (piece is Rook)
            {
                return Resources.BlackRook;
            }
            else if (piece is Queen)
            {
                return Resources.BlackQueen;
            }
            else if (piece is King)
            {
                return Resources.BlackKing;
            }
            else
            {
                throw new ArgumentException("Cannot find a visual representation for [ " + piece.GetType() + " ].");
            }
        }
    }
}
